<template>
    <div class="app-container"
         v-loading.fullscreen.lock="allLoading"
         element-loading-text="拼命处理中,请耐心等待"
         element-loading-spinner="el-icon-loading"
         element-loading-background="rgba(0, 0, 0, 0.8)"
    >

        <el-form :model="mainTable.queryParams" ref="queryForm" size="small" :inline="true" v-show="mainTable.showSearch"
                 label-width="auto">
            <el-form-item label="组织" prop="orgName">
                <el-input   v-model="mainTable.queryParams.orgName" @keyup.enter.native="handleQuery" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="描述" prop="description">
                <el-input   v-model="mainTable.queryParams.description" @keyup.enter.native="handleQuery" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <SksStatusSelect
                    :form-data="mainTable.queryParams"
                    prop-name="status"
                    :type="2"
                    :unshiftOptionList="[{value:undefined,label:'全部'}]"
                    @change="handleQuery" >
                </SksStatusSelect>

            </el-form-item>
            <template v-if="false">
                <el-form-item>
                    <el-radio-group v-model="mainTable.queryParams.delFlag" style="margin-bottom: 30px;" @change="handleQuery()">
                        <el-radio-button >正常</el-radio-button>
                        <el-radio-button label="1">回收站</el-radio-button>
                    </el-radio-group>
                </el-form-item>
            </template>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <SksTable :mainTable="mainTable" @refresh="getMainList">
            <template slot="top">
                <el-col :span="1.5">
                    <el-button
                        type="primary"
                        plain
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['system:organize:add']"
                    >新增
                    </el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button
                        type="success"
                        plain
                        icon="el-icon-edit"
                        size="mini"
                        :disabled="!sksUtils.safeGet(mainTable,`currentRow.${mainTable.uniqueId}`)"
                        @click="handleUpdate(mainTable.currentRow)"
                        v-hasPermi="['system:organize:edit']"
                    >修改
                    </el-button>
                </el-col>
            </template>
            <template slot="default">
            </template>
            <template slot="tableColumnList-before">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column type="index" label="序号" align="center"/>
            </template>
        </SksTable>
        <OrganizePageAddFromDialog ref="organizePageAddFromDialogRef"></OrganizePageAddFromDialog>
    </div>
</template>

<script>
import { listOrganize, getOrganize, delOrganize, addOrganize, updateOrganize } from "/src/api/system/organize";
import {sksPageMixin} from "sks-plugin-el-erp/lib/sks-page";
import {sksParamColumn, sksQueryConfigMapToList} from "sks-plugin-el-erp/lib/sks-app-utils";

import OrganizePageAddFromDialog from './OrganizePageAddFromDialog'


export default {
    name: "Organize",
    components: {
        OrganizePageAddFromDialog,
    },
    mixins: [
        sksPageMixin,
    ],
    data() {
        return {
            defaultQueryParams:{
                //组织
                orgName: undefined,
                //描述
                description: undefined,
                //状态
                status: undefined,
            },


        };
    },
    created() {
        this.getMainList();
    },
    methods: {
        initMainTableParam(){
            let tableColumnList = this.sksUtils.newTableColumnList([
                {
                    prop:'orgName',
                    label: '组织',
                    htmlType: '',
                },
                {
                    prop:'description',
                    label: '描述',
                    htmlType: '',
                },
                {
                    prop:'remark',
                    label: '备注',
                    htmlType: '',
                },
                {
                    prop:'status',
                    label: '状态',
                    htmlType: '',
                },
            ]);
            console.log("initMainTableParam.tableColumnList",tableColumnList)
            return {
                //业务名称,通常用业务表名
                ownerName: `sys_organize`,
                uniqueId: `orgId`,

                //使用 tableColumnList 渲染
                tableColumnListEnable: true,
                //表列 会根据 sksAppName 自动查询后台配置
                tableColumnList: tableColumnList,

                queryParamsColumnListEnable: false,
                //搜索字段 会根据 sksAppName 自动查询后台配置
                queryParamsColumnList: [],

            }
        },
        getMainList(){
            let queryParams = this.mainTable.queryParams;

            this.sksUtils.resetSksTableBefore(this.mainTable)

            listOrganize(queryParams).then(res=>{
                this.sksUtils.setSksTableDataByPage(this.mainTable,res.data)
            })
        },
        handleAdd(){
            this.$refs.organizePageAddFromDialogRef.show({
                form: {
                    virtualChangeBitFlag: this.sksUtils.CHANGE_BIT_FLAG.add,
                },
                dialogInfo: {
                    title: '新增组织',
                    submitCallbackSuccess: ({resData}) => {
                        this.getMainList()
                    },
                },
            })
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.$refs.organizePageAddFromDialogRef.showByOrgId({
                orgId: row.orgId,
                virtualChangeBitFlag: this.sksUtils.CHANGE_BIT_FLAG.modify,
                dialogInfo: {
                    title: '修改组织',
                    submitCallbackSuccess: ({resData}) => {
                        this.getMainList()
                    },
                },
            })
        },
    }
};
</script>
